package net.zjitc.controller;

import net.zjitc.domain.User;
import net.zjitc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping
    public Boolean add(@RequestBody User user) {
        return userService.addUser(user);
    }

    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable("id") Integer id) {
        return userService.deleteUser(id);
    }

    @GetMapping("/{id}")
    public User findById(@PathVariable("id") Integer id) {
        return userService.findById(id);
    }

    @PutMapping
    public Boolean update(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @PostMapping("/{currentPage}/{pageSize}")
    public List<User> getPage(@PathVariable("currentPage") int currentPage,
                              @PathVariable("pageSize") int pageSize,
                              @RequestBody User user) {
        return userService.findPage(currentPage, pageSize, user);
    }
}
